package cn.zymall.user.controller;


import cn.zymall.common.controller.crud.BaseController;
import cn.zymall.common.model.Admin;
import cn.zymall.user.service.AdminService;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * (Admin)表控制层
 *
 * @author makejava
 * @since 2020-08-18 10:39:38
 */
@RestController
@RequestMapping("admin")
public class AdminController extends BaseController<AdminService,Admin> {

	@Autowired
	AdminService adminService;
	/*
	 * @Author 欧泽昌
	 * @Description //查询全部管理员
	 * @Date 2020/8/25 15:59
	 * @Param []
	 * @return java.util.List<cn.zymall.common.model.Admin>
	 **/
	@GetMapping("select")
	public List<Admin> selectAll(){
		return adminService.selectAll();
	}
	/**
	 * @Author 欧泽昌
	 * @Description //新增管理员
	 * @Date 2020/8/25 15:59
	 * @Param [bean]
	 * @return boolean
	 **/
	@Override
	public boolean insert(@RequestBody Admin bean) {
		return super.insert(bean);
	}
	/**
	 * @Author 欧泽昌
	 * @Description //修改管理员
	 * @Date 2020/8/25 15:59
	 * @Param [bean]
	 * @return boolean
	 **/
	@Override
	public boolean update(@RequestBody Admin bean) {
		return super.update(bean);
	}

	/**
	 * @Author 欧泽昌
	 * @Description //删除管理员,根据id删除
	 * @Date 2020/8/25 16:00
	 * @Param [id]
	 * @return boolean
	 **/
	@Override
	public boolean delete(String id) {
		System.out.println("--------"+id);
		return super.delete(id);
	}
	/**
	 * @Author 欧泽昌
	 * @Description //批量修改管理员状态
	 * @Date 2020/8/25 16:00
	 * @Param [map]
	 * @return int
	 **/
	@PostMapping("batchUpdate")
	public int batchUpdate(@RequestBody Map map){
		List<Admin> list=null;
		for (Object obj:map.values()) {
			list = JSONObject.parseArray(obj.toString(), Admin.class);
		}
		return adminService.batchUpdate(list);
	}

	/**
	 * @author：th
	 * @Description：账号密码查询
	 * @Param：
	 * @return：
	 **/
	@GetMapping("/adminSign")
	public Admin adminSign(Admin admin){

		System.out.println(admin);
		return adminService.adminSign(admin);
	}

}
